package com.example.qasys;

import okhttp3.*;
import org.junit.jupiter.api.Test;

import java.io.IOException;

public class testCalss {


    @Test
    void test() throws IOException {
        OkHttpClient client = new OkHttpClient();

        MediaType mediaType = MediaType.parse("application/json");
        RequestBody body = RequestBody.create(mediaType, "{\"conversation_id\":\"rlNbWBPoayg5\",\"person_id\":\"kzPdyrxVeQro\",\"message\":\"123\"}");
        Request request = new Request.Builder()
                .url("https://getcody.ai/widget-backend/95ec039a-6342-422c-b128-359f78a42d01/messages")
                .method("POST", body)
                .addHeader("authority", "getcody.ai")
                .addHeader("accept", "application/json, text/plain, */*")
                .addHeader("accept-language", "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6")
                .addHeader("content-type", "application/json")
                .addHeader("origin", "https://getcody.ai")
                .addHeader("referer", "https://getcody.ai/widget/95ec039a-6342-422c-b128-359f78a42d01")
                .addHeader("sec-ch-ua", "\"Microsoft Edge\";v=\"111\", \"Not(A:Brand\";v=\"8\", \"Chromium\";v=\"111\"")
                .addHeader("sec-ch-ua-mobile", "?0")
                .addHeader("sec-ch-ua-platform", "\"Windows\"")
                .addHeader("sec-fetch-dest", "empty")
                .addHeader("sec-fetch-mode", "cors")
                .addHeader("sec-fetch-site", "same-origin")
                .addHeader("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36 Edg/111.0.1661.54")
                .build();

        Response response = client.newCall(request).execute();
        System.out.println(response.body().string());
    }

    @Test
    void test2() throws IOException {
        OkHttpClient client = new OkHttpClient();

        HttpUrl.Builder urlBuilder = HttpUrl.parse("https://getcody.ai/widget-backend/95ec039a-6342-422c-b128-359f78a42d01/messages").newBuilder();
        urlBuilder.addQueryParameter("conversation_id", "rlNbWBPoayg5");
        urlBuilder.addQueryParameter("person_id", "kzPdyrxVeQro");
        urlBuilder.addQueryParameter("per_page", "100");
        urlBuilder.addQueryParameter("page", "1");
        String url = urlBuilder.build().toString();

        Request request = new Request.Builder()
                .url(url)
                .addHeader("authority", "getcody.ai")
                .addHeader("accept", "application/json, text/plain, */*")
                .addHeader("accept-language", "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6")
                .addHeader("referer", "https://getcody.ai/widget/95ec039a-6342-422c-b128-359f78a42d01")
                .addHeader("sec-ch-ua", "\"Microsoft Edge\";v=\"111\", \"Not(A:Brand\";v=\"8\", \"Chromium\";v=\"111\"")
                .addHeader("sec-ch-ua-mobile", "?0")
                .addHeader("sec-ch-ua-platform", "\"Windows\"")
                .addHeader("sec-fetch-dest", "empty")
                .addHeader("sec-fetch-mode", "cors")
                .addHeader("sec-fetch-site", "same-origin")
                .addHeader("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36 Edg/111.0.1661.54")
                .build();

        Response response = client.newCall(request).execute();
        System.out.println(response.body().string());
    }

}

